<template>
  <div v-if="show" class="fontDa">
    <div class="fontDa"  v-for="hzItem in hzTableList" v-if="hzItem" style="margin-bottom: 40px">
<!--      <div class="customTableHeader">-->
<!--        <div class="customTableTitle" @click="open(hzItem)">{{ hzItem.cepingHdglCppmxbInfo.cppName }}</div>-->
<!--      </div>-->
      <div class="h_dw_time"  v-if="hzItem.cepingHdglCppmxbInfo">
        <div style="margin-left: 20px;font-size: 24px">单位：{{ hzItem.cepingHdglCppmxbInfo.sheetDept }}</div>
      </div>
      <div class="">
        <div>
          <div class="biaoTiGi"  v-if="hzItem.cepingHdglCppmxbInfo">
            <span @click="open(hzItem)">{{ hzItem.cepingHdglCppmxbInfo.cppName }}</span>
          </div>
          <el-table ref="report-table" :data="hzItem.tableData" border :span-method="objectSpanMethod">
            <el-table-column  type="index"  label="序号" header-align="center" align="center" width="70"></el-table-column>
            <el-table-column label="被评议对象的基本情况" align="center" min-width="300">
              <el-table-column v-for="col in hzItem.colShowAll" :prop="col.prop" :label="col.label">
              </el-table-column>
            </el-table-column>
            <el-table-column prop="leader" label="对提拔任用该干部的看法" align="center">
              <template slot-scope="leader">
                {{ leader.row.wxOpenid }}
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              prop="caozuo"
              header-align="center"
              align="center"
              width="180">
              <template slot-scope="scope">
                <el-tooltip content="点击可返回该张测评票进行测评分值修改。" placement="top" effect="light" v-if="scope.$index==0">
                  <el-button type="warning" style="margin-left:10px" @click="open(hzItem)">返回测评界面</el-button>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <template v-for="(item,index) in hzItem.questionList">
            <div style="width: 100%;margin-top: 25px;" class="zfheaderbox sub" v-if="item.title">
              <div>{{index+1}}、{{ item.title }}</div>
            </div>
            <div style="width: 100%;" class="zfheaderbox" v-for="ansItem in hzItem.voteAnsList">
<!--              placeholder="新选拔任用领导人员民主评议表"-->
              <el-input
                readonly
                v-if="ansItem.itemId==item.itemId"
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 10}"
                size="medium"
                v-model="ansItem.answer">
              </el-input>
            </div>
          </template>
        </div>
<!--        <div style="width: 100%;" class="zfheaderbox">-->
<!--          <div>*说明：在“对提拔任用该干部的看法”下方合适的评价等级内打划“√”</div>-->
<!--        </div>-->
      </div>
    </div>
  </div>
</template>

<script>
import {wdXuanPiao, wdXuanPiaoXp} from "@/api/ceping/cepinghdglxpxxb";
import {anonymousSelhdidList as selhdidList} from '@/api/ceping/cepinghdglcppmxb'
import { wdXuanPiaoXpNew,xpInfo,xpInfoHz,wdXuanPiaoXpNewSm,xpInfoSm,xpInfoHzSm } from "@/api/ceping/jxevalvote";
import {getObj} from "@/api/ceping/cepinghdglb";
import {getIds as deptsGet} from "@/api/admin/dept";
import {getIds as usersGet} from "@/api/admin/user";

import djDf from "./cpIndexHzDjdf";

export default {
  name: "cpIndexHz",
  components: {
    djDf
  },
  data() {
    return {
      show: true,
      type: "",
      hdId: null,
      xcCode: "",
      xpList: [],//所有选票
      cppList: [],
      cepingHdglb: {},
      deptObj: {},
      userObj: {},
      djxxDjmx: false,
      tableData: [],
      cepingHdglCppmxbInfo: {},
      colShowAll: [],
      questionList: [],
      msgList:[],
      voteAnsList:[],
      hzTableList:[],
      tabsList:[],
      fromPage:'',
      fromXpId:'',
      fromcppId:'',
      userId:''
    }
  },
  methods: {
    init() {
      this.xpList = [];
    },
    //实名打票过来的汇总初始化
    InitHdHz(data){
      this.xcCode = data.xpCode;
      this.tabsList=data.tabsList;
      this.fromPage=data.fromPage;
      this.fromXpId=data.fromXpId;
      this.fromcppId=data.fromcppId;
      this.userId=this.$store.state.user.userInfo.userId;
      this.hdId=data.hdId;
      const params={
        hdId:this.hdId,
        userId:this.userId,
        sheetType:3,
      }
      wdXuanPiaoXpNewSm(params).then(res => {
        var arrData=res.data.data
        this.xpList = arrData;
        this.hzTableList=arrData;
        this.xpList.forEach((item, index) => {
          //获取表头
          this.getHdColum(item.cppId,index);
          //获取表格数据
          //this.getHzData(index);
        })
      })
    },
    //实名打票获取数据
    getHdColum(cppId,index){
      this.hzTableList[index].questionList=[];
      let params ={
        cppId:cppId,
        hdId:this.hdId,
        userId:this.userId
      }
      xpInfoSm(params).then(res => {
        this.hzTableList[index].cepingHdglCppmxbInfo = res.data.data.cepingHdglCppmxbInfo;
        this.hzTableList[index].colShowAll = JSON.parse(res.data.data.cepingHdglCppmxbInfo.hostConfigJson);
        this.msgList = JSON.parse(res.data.data.cepingHdglCppmxbInfo.ruleDetailJson);
        this.msgList.forEach(item=> {
          if (item.itemType == 3) {
            var pushObj={
              answer:'',
              title:item.title,
              itemId:item.itemId,
            }
            this.hzTableList[index].questionList.push(pushObj)
          }
        })
        this.$forceUpdate()
        this.getHdHzData(cppId,index);
        this.$forceUpdate()
      })
    },
    //获取实名打票来的汇总数据
    getHdHzData(cppId,index){
      let params ={
        cppId:cppId,
        sheetType:3,
        hdId:this.hdId,
        userId:this.userId
      }
      xpInfoHzSm(params).then(res => {
        res.data.data.userList.forEach(item=>{
                if(item.rySr){
                  item.rySr = item.rySr.substring(0,7)
                }
              })
        this.hzTableList[index].tableData = res.data.data.userList;
        this.hzTableList[index].voteAnsList = res.data.data.voteAnsList;
        this.$emit('closeLoading')
        this.$forceUpdate()
      })
    },
    //汇总初始化
    initHz(data) {
      this.xcCode = data.xpCode;
      this.tabsList=data.tabsList;
      this.fromPage=data.fromPage;
      this.fromXpId=data.fromXpId;
      this.fromcppId=data.fromcppId;
      let params = {
        xpCode: this.xcCode,
        sheetType:3
      }
      wdXuanPiaoXpNew(params).then(res => {
        this.xpList = res.data.data;
        this.hzTableList=res.data.data;
          this.xpList.forEach((item, index) => {
            //获取表头
            this.getColum(item.cppId,index);
            //获取表格数据
            //this.getHzData(index);
          })
      })
    },
    //获取汇总表格表头
    getColum(cppId,index) {
      var params={
        cppId:cppId,
        xpCode:this.xcCode
      }
      this.hzTableList[index].questionList=[];
      xpInfo(params).then(res => {
        this.hzTableList[index].cepingHdglCppmxbInfo = res.data.data.cepingHdglCppmxbInfo;
        this.hzTableList[index].colShowAll = JSON.parse(res.data.data.cepingHdglCppmxbInfo.hostConfigJson);
        this.msgList = JSON.parse(res.data.data.cepingHdglCppmxbInfo.ruleDetailJson);
        this.msgList.forEach(item=> {
          if (item.itemType == 3) {
            var pushObj={
              answer:'',
              title:item.title,
              itemId:item.itemId,
            }
            this.hzTableList[index].questionList.push(pushObj)
          }
        })
        this.$forceUpdate()
        this.getHzData(cppId,index);
        this.$forceUpdate()
      })
    },
    //获取汇总表格数据
    getHzData(cppId,index) {
      var params={
        xpCode:this.xcCode,
        sheetType:3,
        cppId:cppId
      }
      xpInfoHz(params).then(res => {
        res.data.data.userList.forEach(item=>{
                if(item.rySr){
                  item.rySr = item.rySr.substring(0,7)
                }
              })
        this.hzTableList[index].tableData = res.data.data.userList;
        this.hzTableList[index].voteAnsList = res.data.data.voteAnsList;
        this.$emit('closeLoading')
        this.$forceUpdate()
      })
    },
    //合并单元格
    objectSpanMethod({row, column, rowIndex, columnIndex}) {
      if(column.property=="caozuo"){
        return [99999, 1];
      }
    },
    open(t) {
      var params={
        id:t.cppId,
        clickTab:'ceping3',
        upPageObj:{
          toPage:this.fromPage,
          tpXpId:this.fromXpId,
          cppId:this.fromcppId
        }
      }
      this.$emit('openXp', params);
    },
  }
}
</script>

<style scoped>
.h_dw_time{
  display: flex;
  justify-content: space-between;
}
.sub{
  display: flex;
  justify-content: space-between;
}

.biaoTiGi {
  width: 100%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  font-size: 28px;
  font-weight: bolder;
  /*background: #1f84ec;*/
  background: #b0bde2;
  /*color: #fff;*/
}
.biaoTiGi span:hover{
  color: #1a71fb;
  cursor: pointer;
}
</style>
